--- /dev/null
+>From 1c815bec0324037494840d01fc579f2a3420e624 Mon Sep 17 00:00:00 2001
+From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
+Date: Thu, 27 Nov 2025 13:22:22 +0100
+Subject: [PATCH] core/fxcrt/numerics: Fix incorrect preprocessor check on
+ aarch64
+
+The preprocessor macro to toggle the use of safe_math_arm_impl.h
+currently checks whether __ARMEL__ or __arch64__ are defined. However,
+on aarch64, the actual define is called __aarch64__ not __arch64__:
+
+(sid_arm64-dchroot)glaubitz@amdahl:~$ uname -a
+Linux amdahl 6.12.57+deb13-arm64 #1 SMP Debian 6.12.57-1 (2025-11-05) aarch64 GNU/Linux
+(sid_arm64-dchroot)glaubitz@amdahl:~$ echo | gcc -E -dM -|grep arch
+(sid_arm64-dchroot)glaubitz@amdahl:~$
+
+However, the define __arch64__ is used on sparc64:
+
+(sid_sparc64-dchroot)glaubitz@stadler:~$ uname -a
+Linux stadler 6.17.0-rc5+ #1 SMP Fri Sep 12 20:37:32 UTC 2025 sparc64 GNU/Linux
+(sid_sparc64-dchroot)glaubitz@stadler:~$ echo | gcc -E -dM -|grep arch
+(sid_sparc64-dchroot)glaubitz@stadler:~$
+
+This triggers the use of safe_math_arm_impl.h on sparc64 which causes
+the compiler to emit the "qsub" instruction which is not recongized:
+
+/tmp/ccLEFgM7.s: Assembler messages:
+/tmp/ccLEFgM7.s:10332: Error: Unknown opcode: `qsub'
+/tmp/ccLEFgM7.s:10365: Error: Unknown opcode: `qsub'
+
+Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
+---
+ core/fxcrt/numerics/safe_math_clang_gcc_impl.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/core/fxcrt/numerics/safe_math_clang_gcc_impl.h b/core/fxcrt/numerics/safe_math_clang_gcc_impl.h
+index 58419d5c9..d395ebd3e 100644
+--- core/fxcrt/numerics/safe_math_clang_gcc_impl.h
++++ core/fxcrt/numerics/safe_math_clang_gcc_impl.h
+@@ -14,7 +14,7 @@
+
+ #include "core/fxcrt/numerics/safe_conversions.h"
+
+-#if !defined(__native_client__) && (defined(__ARMEL__) || defined(__arch64__))
++#if !defined(__native_client__) && defined(__ARMEL__)
+ #include "core/fxcrt/numerics/safe_math_arm_impl.h"
+ #define BASE_HAS_ASSEMBLER_SAFE_MATH (1)
+ #else
+--
+2.47.3
+
--- /dev/null
+--- build/build_config.h 2024-03-05 16:50:08.624785549 +0100
++++ build/build_config.h 2024-03-05 16:50:55.616839071 +0100
+@@ -350,6 +350,25 @@
+ #define ARCH_CPU_RISCV64 1
+ #define ARCH_CPU_64_BITS 1
+ #define ARCH_CPU_LITTLE_ENDIAN 1
++#elif defined(__sparc__)
++#define ARCH_CPU_BIG_ENDIAN 1
++#if defined(__arch64__)
++#define ARCH_CPU_64_BITS 1
++#else
++#define ARCH_CPU_32_BITS 1
++#endif
++#elif defined(__m68k__)
++#define ARCH_CPU_32_BITS 1
++#define ARCH_CPU_BIG_ENDIAN 1
++#elif defined(__hppa__)
++#define ARCH_CPU_32_BITS 1
++#define ARCH_CPU_BIG_ENDIAN 1
++#elif defined(__alpha__)
++#define ARCH_CPU_64_BITS 1
++#define ARCH_CPU_LITTLE_ENDIAN 1
++#elif defined(__ia64__)
++#define ARCH_CPU_64_BITS 1
++#define ARCH_CPU_LITTLE_ENDIAN 1
+ #else
+ #error Please add support for your architecture in build/build_config.h
+ #endif